<template>
  <div class="am-u-sm-12">
    <div class="widget am-cf">
      <div class="widget-head am-cf">
        <div class="widget-title am-fl">余额迁移</div>
      </div>
      <div class="widget-body am-fr">
        <div class="am-u-sm-12 am-form ">
          <div class="am-u-sm-12 am-u-md-12 am-u-lg-3">
            <div class="am-form-group">
              <input type="text"  v-model="query.studentName" placeholder="学生姓名"/>
            </div>
          </div>

          <div class="am-u-sm-12 am-u-md-12 am-u-lg-3">
            <div class="am-form-group">
              <input type="text"  v-model="query.studentPhoneNo" placeholder="手机号码"/>
            </div>
          </div>

          <div class="am-u-sm-12 am-u-md-12 am-u-lg-3">
            <div class="am-form-group">
              <input type="text"  v-model="query.operatorName" placeholder="操作人"/>
            </div>
          </div>

          <div class="am-u-sm-12 am-u-md-12 am-u-lg-3">
            <div class="am-form-group">
              <el-date-picker
                v-model="query.startDate"
                type="date"
                placeholder="操作开始时间">
              </el-date-picker>
            </div>
          </div>

          <div class="am-u-sm-12 am-u-md-12 am-u-lg-3">
            <div class="am-form-group">
              <el-date-picker
                v-model="query.endDate"
                type="date"
                placeholder="操作结束时间">
              </el-date-picker>
            </div>
          </div>


          <div class="am-u-sm-12 am-u-md-12 am-u-lg-3 am-u-end">
            <div class="am-form-group">
              <button type="button" class="am-btn am-btn-default am-btn-success"
                      @click="search" ><span class="am-icon-search"></span>查询
              </button>
              <button type="button" class="am-btn am-btn-default am-btn-success"
                      @click="handleExport" ><span class="am-icon-download"></span>导出
              </button>
            </div>
          </div>


        </div>

        <div class="am-u-sm-12">
          <el-table
            :data="tableData"
            border
            stripe
            style="min-width: 100%">
            <el-table-column
              prop="studentName"
              label="学生姓名"
              min-width="120">
            </el-table-column>
            <el-table-column
              prop="studentNo"
              label="学号（誉优）"
              min-width="140">
            </el-table-column>
            <el-table-column
              label="学号（TMS）"
              min-width="140">
              <template scope="scope">
                <div>
                  {{scope.row.studentNo.replace('zy', '')}}
                </div>
              </template>
            </el-table-column>
            <el-table-column
              prop="studentPhoneNo"
              label="手机号"
              min-width="120">
            </el-table-column>
            <el-table-column
              prop="amount"
              label="转移余额"
              min-width="120">
            </el-table-column>
            <el-table-column
              prop="operatorName"
              label="操作人"
              min-width="120">
            </el-table-column>
            <el-table-column
              prop="updateTime"
              label="操作时间"
              min-width="180">
              <template scope="scope">
                <div>{{scope.row.updateTime | formatTime}}</div>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div class="am-u-lg-12 am-cf">
          <div class="am-fr">
            <pagination v-bind:total="total" v-bind:pageNo="pageNo" v-bind:pageSize="pageSize"
                        @paging="loadTableData"/>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import io from '../../lib/io'
  import Pagination from '../base/Pagination'
  export default{
    data: function () {
      return {
        tableData: [],
        total: 0,
        pageSize: 10,
        pageNo: 1,
        query: {
          operatorName : '',
          studentName : '',
          studentPhoneNo : '',
          startDate: '',
          endDate: '',
        },
      }
    },
    components: {
      Pagination,
    },
    mounted: function () {
      $(window).smoothScroll()
    },
    created: function () {
      this.loadTableData(this.pageNo)
    },
    methods: {
      search: function () {
        this.loadTableData(1)
      },
      loadTableData: function (pageNo) {
        var _this = this
        _this.pageNo = pageNo || _this.pageNo || 1
        var startDate = this.query.startDate ? this.$options.filters.formatDate(this.query.startDate) : ''
        var endDate = this.query.endDate ? this.$options.filters.formatDate(this.query.endDate) : ''
        io.post(io.findCompleteTmsBalanceTransferPage, $.extend({
          pageNo: _this.pageNo,
          pageSize: _this.pageSize
        }, _this.query, {
          startDate: startDate,
          endDate: endDate,
        }), function (ret) {
          if (ret.success) {
            _this.total = ret.data.total
            _this.tableData = ret.data.list
          } else {
            _this.$alert(ret.desc)
          }
        })
      },

      //导出学生退费信息
      handleExport:function(){
        var startDate = this.query.startDate ? this.$options.filters.formatDate(this.query.startDate) : ''
        var endDate = this.query.endDate ? this.$options.filters.formatDate(this.query.endDate) : ''
        io.downloadFile(io.exportCompleteTmsBalanceTransfer , Object.assign({},this.query, {
          startDate:startDate,
          endDate:endDate
        }) )
      },
    }
  }
</script>
<style lang="less" scpoed>
  .am-form {
    &>.am-u-sm-12:nth-child(4n + 1) {
      clear: both;
    }
  }
</style>

